<template>
    <el-main class="main-content">
        <!-- 欢迎横幅 -->
        <div class="welcome-banner">
            <div class="banner-content">
                <h1>欢迎来到畜牧育种管理系统!</h1>
                <p>智能化管理您的畜牧养殖业务，提高育种效率和经济效益</p>
            </div>
            <!-- <img src="@/assets/sheep-flock-bg.jpg" alt="畜牧群" class="banner-image"> -->
            <div class="datetime-container">
                <div class="current-datetime">
                    <span>欢迎您！</span>
                    <div class="date-display">{{ currentDate }}</div>
                    <div class="time-display">{{ currentTime }}</div>
                </div>

            </div>
        </div>

        <!-- 统计卡片 -->
        <div class="stats-cards">
            <el-row :gutter="20">
                <el-col :span="6">
                    <div class="stat-card">
                        <div class="stat-icon">
                            <el-icon>
                                <User />
                            </el-icon>
                        </div>
                        <div class="stat-content">
                            <h3>总畜牧数</h3>
                            <p class="stat-number">1,248</p>
                            <p class="stat-trend">+5.2% 较上月</p>
                        </div>
                    </div>
                </el-col>
                <el-col :span="6">
                    <div class="stat-card">
                        <div class="stat-icon">
                            <el-icon>
                                <TrendCharts />
                            </el-icon>
                        </div>
                        <div class="stat-content">
                            <h3>育种成功率</h3>
                            <p class="stat-number">87.3%</p>
                            <p class="stat-trend">+2.1% 较上月</p>
                        </div>
                    </div>
                </el-col>
                <el-col :span="6">
                    <div class="stat-card">
                        <div class="stat-icon">
                            <el-icon>
                                <Warning />
                            </el-icon>
                        </div>
                        <div class="stat-content">
                            <h3>健康预警</h3>
                            <p class="stat-number">23</p>
                            <p class="stat-trend">-12 较昨日</p>
                        </div>
                    </div>
                </el-col>
                <el-col :span="6">
                    <div class="stat-card">
                        <div class="stat-icon">
                            <el-icon>
                                <Coin />
                            </el-icon>
                        </div>
                        <div class="stat-content">
                            <h3>月度收益</h3>
                            <p class="stat-number">¥89,450</p>
                            <p class="stat-trend">+8.7% 较上月</p>
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>

        <!-- 快捷操作 -->
        <div class="quick-actions">
            <h3>快捷操作</h3>
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-card class="action-card" @click="GoUserInfo" shadow="hover">
                        <el-icon>
                            <Plus />
                        </el-icon>
                        <span>新增用户</span>
                    </el-card>
                </el-col>
                <el-col :span="6">
                    <el-card class="action-card" shadow="hover">
                        <el-icon>
                            <Edit />
                        </el-icon>
                        <span>育种登记</span>
                    </el-card>
                </el-col>
                <el-col :span="6">
                    <el-card class="action-card" @click="GoPurchase" shadow="hover">
                        <el-icon>
                            <Document />
                        </el-icon>
                        <span>个体采购</span>
                    </el-card>
                </el-col>
                <el-col :span="6">
                    <el-card class="action-card" shadow="hover">
                        <el-icon>
                            <Picture />
                        </el-icon>
                        <span>生成报表</span>
                    </el-card>
                </el-col>
            </el-row>
        </div>

        <!-- 最近活动 -->
        <div class="recent-activities">
            <h3>最近活动</h3>
            <el-timeline>
                <el-timeline-item timestamp="2024-10-10 14:30" placement="top">
                    <el-card class="notification-card">
                        <div class="card-header">
                            <h4>财务部通知您！</h4>
                            <el-badge :value="unreadCount" :max="99" class="notification-badge">
                                <el-icon size="16" class="notification-icon">
                                    <Bell />
                                </el-icon>
                            </el-badge>
                        </div>
                        <p>本月您的工资已到账，已转入尾号3376的银行卡中，请注意查收！</p>
                    </el-card>
                </el-timeline-item>
                <el-timeline-item timestamp="2024-01-15 10:15" placement="top">
                    <el-card>
                        <h4>健康检查完成</h4>
                        <p>完成全部畜牧的健康检查，发现3只需要特殊护理</p>
                    </el-card>
                </el-timeline-item>
                <el-timeline-item timestamp="2024-01-14 16:45" placement="top">
                    <el-card>
                        <h4>月度报表生成</h4>
                        <p>1月份畜牧养殖月度报表已生成并发送给相关负责人</p>
                    </el-card>
                </el-timeline-item>
            </el-timeline>
        </div>
    </el-main>
</template>

<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from 'vue'
import {
    House,
    User,
    TrendCharts,
    Document,
    Setting,
    Plus,
    Edit,
    Picture,
    Warning,
    Coin,
    ArrowDown,
    Calendar,
    SwitchButton,
    Bell
} from '@element-plus/icons-vue'
import UserInfo from './PermissionPage/UserInfo.vue'
import { useRouter } from 'vue-router'
const router = useRouter()

const GoUserInfo = () => {
    router.push("/UserInfo")
}
const GoPurchase = () => {
    router.push("/Purchase")
}

// 实时时间显示
const currentDate = ref('')
const currentTime = ref('')
let timer: number | null = null

// 未读消息数量
const unreadCount = ref(1)

// 更新时间函数
const updateDateTime = () => {
    const now = new Date()

    // 格式化日期：年月日
    const year = now.getFullYear()
    const month = String(now.getMonth() + 1).padStart(2, '0')
    const day = String(now.getDate()).padStart(2, '0')
    const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
    const weekday = weekdays[now.getDay()]

    currentDate.value = `${year}年${month}月${day}日 ${weekday}`

    // 格式化时间：时分秒
    const hours = String(now.getHours()).padStart(2, '0')
    const minutes = String(now.getMinutes()).padStart(2, '0')
    const seconds = String(now.getSeconds()).padStart(2, '0')

    currentTime.value = `${hours}:${minutes}:${seconds}`
}

// 组件挂载时启动定时器
onMounted(() => {
    updateDateTime() // 立即更新一次
    timer = setInterval(updateDateTime, 1000) // 每秒更新
})

// 组件卸载时清除定时器
onUnmounted(() => {
    if (timer) {
        clearInterval(timer)
    }
})
</script>

<style scoped>
.home-page {
    height: 100vh;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* 顶部导航栏样式 */
.header {
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 0;
    height: 50px !important;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 20px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    width: 32px;
    height: 32px;
}

.system-title {
    font-size: 22px;
    font-weight: bold;
    color: #304156;
}

.user-info {
    display: flex;
    align-items: center;
}

.el-dropdown-link {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: #3f4044;
    /* size: 20; */
}

.el-dropdown-link:hover {
    color: #409EFF;
}

/* 主容器样式 */
.main-container {
    height: calc(100vh - 60px);
}

/* 侧边栏样式 */
.sidebar {
    background-color: #304156;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.1);
}

.el-menu-vertical {
    border-right: none;
    height: 100%;
}

.el-menu-vertical .el-menu-item:hover {
    background-color: #263445 !important;
}

.el-menu-vertical .el-sub-menu__title:hover {
    background-color: #263445 !important;
}

/* 主内容区域样式 */
.main-content {
    padding: 20px;
    overflow-y: auto;
}

/* 欢迎横幅样式 */
.welcome-banner {
    background: var(--gradient-primary);
    border-radius: 16px;
    padding: 40px;
    color: white;
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-medium);
    position: relative;
    overflow: hidden;
}

.welcome-banner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    pointer-events: none;
}

.banner-content h1 {
    font-size: 28px;
    margin-bottom: 10px;
    font-weight: 600;
}

.banner-content p {
    font-size: 16px;
    opacity: 0.9;
}

.banner-image {
    width: 200px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    opacity: 0.8;
}

/* 实时时间显示样式 */
.datetime-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.current-datetime {
    text-align: center;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 200px;
}

.date-display {
    font-size: 16px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.95);
    margin-bottom: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.time-display {
    font-size: 24px;
    font-weight: bold;
    color: #ffffff;
    font-family: 'Courier New', monospace;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: 1px;
}

.calendar-icon {
    color: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.calendar-icon:hover {
    color: #ffffff;
    transform: scale(1.1);
}

/* 统计卡片样式 */
.stats-cards {
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-light);
    border: 1px solid var(--border-light);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(139, 126, 216, 0.02) 0%, rgba(74, 144, 226, 0.02) 100%);
    pointer-events: none;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-heavy);
    border-color: var(--primary-purple);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}

.stat-card:nth-child(1) .stat-icon {
    background: var(--gradient-primary);
    box-shadow: 0 4px 12px rgba(139, 126, 216, 0.3);
}

.stat-card:nth-child(2) .stat-icon {
    background: linear-gradient(135deg, #A8A0E8 0%, #6BA6F2 100%);
    box-shadow: 0 4px 12px rgba(168, 160, 232, 0.3);
}

.stat-card:nth-child(3) .stat-icon {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

.stat-card:nth-child(4) .stat-icon {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    box-shadow: 0 4px 12px rgba(67, 233, 123, 0.3);
}

.stat-content h3 {
    font-size: 14px;
    color: var(--text-light);
    margin: 0 0 8px 0;
    font-weight: 500;
}

.stat-number {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-primary);
    margin: 0 0 5px 0;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-trend {
    font-size: 12px;
    color: var(--success-color);
    margin: 0;
    font-weight: 500;
}

/* 快捷操作样式 */
.quick-actions {
    margin-bottom: 30px;
}

.quick-actions h3 {
    margin-bottom: 24px;
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.action-card {
    text-align: center;
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid var(--border-light);
    background: var(--bg-card);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.action-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-light);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.action-card:hover {
    border-color: var(--primary-purple);
    transform: translateY(-4px);
    box-shadow: var(--shadow-medium);
}

.action-card:hover::before {
    opacity: 1;
}

.action-card .el-icon {
    font-size: 36px;
    color: var(--primary-purple);
    margin-bottom: 12px;
    display: block;
    transition: all 0.3s ease;
}

.action-card:hover .el-icon {
    color: var(--secondary-blue);
    transform: scale(1.1);
}

.action-card span {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    position: relative;
    z-index: 1;
}

/* 最近活动样式 */
.recent-activities h3 {
    margin-bottom: 24px;
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 通知卡片样式 */
.notification-card {
    position: relative;
    border-left: 4px solid #d24545;
    transition: all 0.3s ease;
}

.notification-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(245, 108, 108, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-header h4 {
    margin: 0;
    color: #f56c6c;
    font-size: 16px;
    font-weight: 600;
}

.notification-badge {
    position: relative;
}

.notification-icon {
    color: #f56c6c;
    transition: all 0.3s ease;
}

.notification-icon:hover {
    color: #e64340;
    transform: scale(1.1);
}

/* 徽章样式自定义 */
:deep(.notification-badge .el-badge__content) {
    background: linear-gradient(135deg, #f56c6c 0%, #e64340 100%);
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(245, 108, 108, 0.4);
    font-size: 12px;
    font-weight: bold;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0% {
        transform: scale(1);
        box-shadow: 0 2px 6px rgba(245, 108, 108, 0.4);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 4px 12px rgba(245, 108, 108, 0.6);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 2px 6px rgba(245, 108, 108, 0.4);
    }
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .welcome-banner {
        flex-direction: column;
        text-align: center;
    }

    .banner-image {
        margin-top: 20px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 200px !important;
    }

    .stat-card {
        margin-bottom: 15px;
    }

    .action-card {
        margin-bottom: 15px;
    }
}

/* 退出登录对话框样式 */
.logout-dialog {
    border-radius: 12px;
    overflow: hidden;
}

.logout-dialog-content {
    padding: 30px 20px;
    text-align: center;
}

.logout-icon-container {
    margin-bottom: 20px;
    animation: pulse 2s infinite;
}

.logout-warning-icon {
    filter: drop-shadow(0 4px 8px rgba(245, 108, 108, 0.3));
}

.logout-title {
    font-size: 18px;
    font-weight: 600;
    color: #303133;
    margin: 0 0 10px 0;
    line-height: 1.4;
}

.logout-subtitle {
    font-size: 14px;
    color: #909399;
    margin: 0;
    line-height: 1.5;
}

.logout-dialog-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    background-color: #f8f9fa;
    border-top: 1px solid #e4e7ed;
}

.cancel-button {
    min-width: 100px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.cancel-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.confirm-logout-button {
    min-width: 120px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.confirm-logout-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 108, 108, 0.3);
}

/* 脉冲动画 */
@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* 对话框标题样式 */
:deep(.logout-dialog .el-dialog__header) {
    padding: 20px 24px;
    margin: 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 1px solid #e4e7ed;
}

:deep(.logout-dialog .el-dialog__title) {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
}

:deep(.logout-dialog .el-dialog__body) {
    padding: 0;
}

:deep(.logout-dialog .el-dialog__footer) {
    padding: 0;
}
</style>